<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>KBX TOB商品列表</title>
    <script src="__PUBLIC__/echarts/echarts.min.js"></script>

    <link rel="stylesheet" href="__PUBLIC__/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="__PUBLIC__/font-awesome/css/font-awesome.min.css" media="all">
    <link rel="stylesheet" href="__CSS__/admin.css"  media="all">
    <style>
        #standard tr th,td{
            text-align:center
        }
    </style>
</head>

<body>
<div class="layui-fluid main">
    <fieldset class="layui-elem-field site-demo-button" style="margin-top: 30px;border:0">
        <div class="layui-form-item" style="float: left;">
            <form class="layui-form serch" action="/admin/standard/index" method="post">
                <div class="layui-form-item" style="float: left;">
                    <div class="layui-input-inline">
                        <input type="text" name="name" lay-verify="name" value="{if isset($wherelist['name'])}{$wherelist['name']}{/if}" autocomplete="off" placeholder="商品ID / 商品名称 / 简介" class="layui-input layui-btn-sm">
                    </div>
                    <div class="layui-input-inline">
                        <select name="type" id="type">
                            <option value="">商品类型</option>
                            <option value="1" {if isset($wherelist['type'])&&$wherelist['type']=='1'}selected{/if}>行程商品</option>
                            <option value="2" {if isset($wherelist['type'])&&$wherelist['type']=='2'}selected{/if}>资源商品</option>
                        </select>
                    </div>
                    <!--<div class="layui-input-inline">-->
                        <!--<select name="topCate" id="topCate">-->
                            <!--<option value="">顶级分类</option>-->
                            <!--{notempty name="$topCate"}-->
                            <!--{volist name='topCate' id='vo'}-->
                            <!--<option value="{$vo.id}" {notempty name='$wherelist.topCate'}{if $wherelist.topCate==$vo.id}selected{/if}{/notempty}>{$vo.name}</option>-->
                            <!--{/volist}-->
                            <!--{/notempty}-->
                        <!--</select>-->
                    <!--</div>-->
                    <div class="layui-input-inline">
                        <select name="tagid" id="tagid">
                            <option value="">详细分类</option>
                            {notempty name="$tags"}
                            {volist name='tags' id='vo'}
                            <option value="{$vo.tag_id}" {notempty name='$wherelist.tagid'}{if $wherelist.tagid==$vo.tag_id}selected{/if}{/notempty}>{$vo.tag_name}</option>
                            {/volist}
                            {/notempty}
                        </select>
                    </div>
                    <!--<div class="layui-input-inline">-->
                        <!--<select name="status" id="status">-->
                            <!--<option value="">是否启用</option>-->
                            <!--<option value="1" {if isset($wherelist['status'])&&$wherelist['status']=='1'}selected{/if}>启用</option>-->
                            <!--<option value="0" {if isset($wherelist['status'])&&$wherelist['status']=='0'}selected{/if}>禁用</option>-->
                        <!--</select>-->
                    <!--</div>-->
                    <div class="layui-input-inline">
                        <select name="city_id" lay-search="">
                            <option value="">请选择城市</option>
                            {foreach name='cityList' id='city'}
                            <option value="{$city.id}" {if isset($wherelist['city_id'])&&$wherelist['city_id']==$city['id']}selected{/if}>{$city.name}</option>
                            {/foreach}
                        </select>
                    </div>
                    <div class="layui-input-inline">
                        <select name="supplier_id" lay-search="">
                            <option value="">请选择供应商</option>
                            {foreach name='supplierList' id='supplier'}
                            <option value="{$supplier.id}" {if isset($wherelist['supplier_id'])&&$wherelist['supplier_id']==$supplier['id']}selected{/if}>{$supplier.name}</option>
                            {/foreach}
                        </select>
                    </div>
                    <div class="layui-input-inline">
                        <select name="show_toB">
                            <option value="">TOB上架状态</option>
                            <option value="1" {if isset($wherelist['show_toB'])&&$wherelist['show_toB']=='1'}selected{/if}>已上架</option>
                            <option value="0" {if isset($wherelist['show_toB'])&&$wherelist['show_toB']=='0'}selected{/if}>未上架</option>
                        </select>
                    </div>
                    <div class="layui-input-inline">
                        <select name="auto_on_sale">
                            <option value="">小程序模板</option>
                            <option value="1" {if isset($wherelist['auto_on_sale'])&&$wherelist['auto_on_sale']=='1'}selected{/if}>是</option>
                            <option value="0" {if isset($wherelist['auto_on_sale'])&&$wherelist['auto_on_sale']=='0'}selected{/if}>否</option>
                        </select>
                    </div>
                    <input type="hidden" name="order_param" value="">
                    <button class="layui-btn layui-btn-danger layui-btn-sm searchBtn" lay-submit="" lay-filter="serch">搜索</button>
                    <!--<a href="{:url('admin/standard/add')}" target="_blank" class="layui-btn layui-btn-sm">-->
                        <!--新建标品-->
                    <!--</a>-->
                </div>
            </form>
        </div>
    </fieldset>
    <table class="layui-table" lay-size="sm" lay-even="" lay-skin="line" id="standard">
        <colgroup>
            <col width="50">
            <col width="200">
            <col width="70">
            <col width="200">
            <col width="60">
            <col width="120">
            <col width="70">
            <col width="70">
            <col width="70">
            <col width="100">
            <col width="70">
            <col width="100">
        </colgroup>
        <thead>
        <tr>
            <th >商品ID</th>
            <th >商品名称</th>
            <th >类型</th>
            <th >简介</th>
            <th >真实销量</th>
            <th >
                <span>展示销量</span>
                <span class="layui-table-sort layui-inline">
                    <i class="layui-edge layui-table-sort-asc salesSortAsc" title="升序"></i>
                    <i class="layui-edge layui-table-sort-desc salesSortDesc" title="降序"></i>
                </span>
            </th>
            <th >
                <span>浏览量</span>
                <span class="layui-table-sort layui-inline">
                    <i class="layui-edge layui-table-sort-asc viewSortAsc" title="升序"></i>
                    <i class="layui-edge layui-table-sort-desc viewSortDesc" title="降序"></i>
                </span>
            </th>
            <th >小程序模板</th>
            <th >推荐</th>
            <th >权重排序</th>
            <th >上架状态</th>
            <th >操作</th>
        </tr>
        </thead>
        <tbody>
        {volist name="list" id="vo"}
        <tr>
            <td>{$vo.id}</td>
            <td>{$vo.name}</td>
            <td data-code="{notempty name='$vo.goods_tcode'}{$vo.goods_tcode}{/notempty}" class="showGoodsCode">
                {if $vo.type==1}
                行程
                {elseif $vo.type==2}
                资源
                {/if}
                {if $vo.show==1}
                <span class="layui-badge layui-bg-green myselfgoods" data-id="{$vo.goods_id}">自营</span>
                {else}
                <span class="layui-badge layui-bg-green viatorgoods" data-id="{$vo.goods_id}">viator</span>
                {/if}

                {if !empty($vo.trip_id)}
                <a class="layui-badge layui-bg-orange" target="_blank" href="{:url('admin/product/productmake',['id'=>$vo['trip_id']])}">产品</a>
                {/if}

            </td>
            <td>{$vo.introduce}</td>
            <td>{$vo.real_sold|default=0}</td>
            <td>{$vo.goodssales|default=0}</td>
            <td>{$vo.view_count|default=0}</td>
            <td>
                <form class="layui-form" action="">
                    <div class="layui-form-item">
                        <div class="layui-input-block" style="margin:10px">
                            <input type="checkbox" name="auto_on_sale" value="1" data-id="{$vo.id}" lay-filter="changeAutoOnSale" lay-skin="switch" <?php if($vo['auto_on_sale']==1){ echo 'checked';} ?> lay-text="是|否">
                        </div>
                    </div>
                </form>
            </td>
            <td>
            <form class="layui-form" action="">
            <div class="layui-form-item">
            <div class="layui-input-block" style="margin:10px">
            <input type="checkbox" name="is_recommend" value="1" data-id="{$vo.id}" lay-filter="changeRecommend" lay-skin="switch" <?php if($vo['is_recommend']==1){ echo 'checked';} ?> lay-text="是|否">
                        </div>
                    </div>
                </form>
            </td>
            <td>
                <form class="layui-form" action="">
                    <div class="layui-form-item">
                        <div class="layui-input-block" style="margin:10px">
                            <input type="number" name="sortNum" old-value="{$vo.sortNum}" value="{$vo.sortNum}" data-id="{$vo.id}" class="layui-input" />
                        </div>
                    </div>
                </form>
            </td>
            <td>
                {if $vo['show_toB']==1}
                <span style="color:green;font-weight: bold;">已上架</span>
                {else}
                <span style="color:red;font-weight: bold;">未上架</span>
                {/if}
            </td>

            <td class="operation-menu">
                {if $vo.type==1}
                {if $vo.page_index==1}
                <a href="{:url('admin/standard/add',['id'=>$vo.id])}" class="layui-btn layui-btn-xs layui-btn-info" target="_blank"  style="margin-right: 0;margin-top:2px;font-size:12px;margin-bottom:4px">编辑</a>
                {elseif $vo.page_index==2}
                <a href="{:url('admin/standard/process',['id'=>$vo.id])}" class="layui-btn layui-btn-xs layui-btn-info" target="_blank"  style="margin-right: 0;margin-top:2px;font-size:12px;margin-bottom:4px">编辑</a>
                {elseif $vo.page_index==3}
                <a href="{:url('admin/standard/savebasic',['id'=>$vo.id])}" class="layui-btn layui-btn-xs layui-btn-info" target="_blank"  style="margin-right: 0;margin-top:2px;font-size:12px;margin-bottom:4px">编辑</a>
                {elseif $vo.page_index==4}
                <a href="{:url('admin/product/setsection',['id'=>$vo.id])}" class="layui-btn layui-btn-xs layui-btn-info" target="_blank"  style="margin-right: 0;margin-top:2px;font-size:12px;margin-bottom:4px">编辑</a>
                {elseif $vo.page_index==5}
                <a href="{:url('admin/standard/savegoods',['id'=>$vo.id])}" class="layui-btn layui-btn-xs layui-btn-info" target="_blank"  style="margin-right: 0;margin-top:2px;font-size:12px;margin-bottom:4px">编辑</a>
                {else}
                <a href="{:url('admin/standard/detail',['id'=>$vo.id])}" class="layui-btn layui-btn-xs layui-btn-info setStandardInfo"  style="margin-right: 0;margin-top:2px;font-size:12px;margin-bottom:4px">编辑</a>
                {/if}
                {else}
                <a href="{:url('admin/standard/detail',['id'=>$vo.id])}" class="layui-btn layui-btn-xs layui-btn-info setStandardInfo"  style="margin-right: 0;margin-top:2px;font-size:12px;margin-bottom:4px">编辑</a>
                {/if}
                <a class="layui-btn layui-btn-xs layui-btn-danger delete" codeid="{$vo.id}" style="margin-right: 0;margin-top:2px;font-size:12px;margin-bottom:4px">删除</a><br>

                {if $vo.show_toB==1}
                <a codeid="{$vo.id}" class="layui-btn layui-btn-xs layui-btn-danger downPro"  style="margin-right: 0;margin-top:2px;font-size:12px;">下架ToB</a><br>
                {else}
                <a codeid="{$vo.id}" class="layui-btn layui-btn-xs layui-btn-info openPro"  style="margin-right: 0;margin-top:2px;font-size:12px;background: #51a954">上架ToB</a><br>
                {/if}
                <!--{notempty name='$vo.goods_id'}-->
                <!--<a href="{:url('admin/goods/addclassify')}?id={$vo.goods_id}" class="layui-btn layui-btn-xs layui-btn-warm a_menu"  style="margin-right: 0;margin-top:2px;font-size:12px;background: #51a954">商品套餐</a><br>-->
                <!--<a href="{:url('admin/goods/personsedit')}?id={$vo.goods_id}&standard_id={$vo.id}" class="layui-btn layui-btn-xs layui-btn-warm"  style="margin-right: 0;margin-top:2px;font-size:12px;background: darkslategrey">商品价格</a><br>-->
                <!--{/notempty}-->
                <!--<a href="{:url('admin/standard/roomconfig')}?id={$vo.id}" class="layui-btn layui-btn-xs layui-btn-warm setRoom"  style="margin-right: 0;margin-top:2px;font-size:12px;">酒店房型</a><br>-->
            </td>
        </tr>
        {/volist}
        </tbody>
    </table>
    <div>{$list->render()}</div>
    <div id="ceshi" style="display:none;">
        <style>
            .isok,.notok{
                font-size: 24px;line-height:24px;
            }
            .isok{
                color: #4caf50;
            }
            .notok{
                color: #ff5722;
            }
        </style>

        <div class="layui-row">
            <!--基础信息-->
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-body">
                        <div class="box">
                            <div style="margin-left:20px;">
                                <form class="layui-form" id="checkInfo">

                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script src="__PUBLIC__/layui/layui.js"></script>
    <script src="__PUBLIC__/jquery/jquery.min.js"></script>
    <script type="text/javascript">
        layui.use(['layer','form','element'],function(){
            var layer = layui.layer;
            var form = layui.form;
            var element = layui.element;
            var $ = layui.jquery;
            $('.a_menu').click(function(){
                var url = $(this).attr('href');
                var a = 0;
                $.ajax({
                    url:url
                    ,async:false
                    ,success:function(res){
                        if(res.code == 0) {
                            layer.msg(res.msg);
                            a = 1;
                        }
                    }
                });
                if(a === 0) {
                    layer.open({
                        type:2,
                        content:url,
                        area: ['80%', '90%'],
                        end:function(){
                            location.reload();
                        }
                    });
                }
                return false;
            });
            //展示行程编码
            var showGoodsCodeIndex = 0;
            $('.showGoodsCode').hover(function () {
                //鼠标悬停
                var goodsCode = $(this).attr('data-code');
                if(goodsCode!='' && goodsCode!=undefined){
                    showGoodsCodeIndex = layer.tips($(this).attr('data-code'),this,{time:0})
                }
            },function () {
                //鼠标离开
                layer.close(showGoodsCodeIndex);
            })
            //配置房型
            $(".setRoom").click(function(){
                var url = $(this).attr('href');
                layer.open({
                    type:2,
                    content:url,
                    area: ['50%', '90%'],
                    end:function(){
                        location.reload();
                    }
                });
                return false;
            })
            $(".delete").click(function(){
                var id = $(this).attr('codeid');
                layer.confirm("您确认删除此标品吗？",function(index){
                    $.post("/admin/standard/delete",{id:id},function(res){
                        layer.msg(res.msg);
                        if(res.code == 1) {
                            setTimeout(function(){
                                location.href = res.url;
                            },1500)
                        }
                    },'json')
                })
            });
            //下架标品
            $(".downPro").click(function(){
                var id = $(this).attr('codeid');
                layer.confirm("您确定从ToB系统下架此标品吗？",function(index){
                    $.post("/admin/standard/changeToB",{'id':id,'show_toB':0},function(res){
                        layer.msg(res.msg);
                        if(res.code == 1) {
                            setTimeout(function(){
                                location.href = res.url;
                            },1500)
                        }
                    },'json')
                })
            })
            var checkProTimer = null;
            var upPro = true;
            $(".openPro").click(function(){
                var id = $(this).attr('codeid');
                $.post("/admin/standard/checkProInfo",{'id':id},function(res){
                    var list = res.data.tips;
                    var goods_id = res.data.goods_id;
                    if(list.length<1){
                        layer.msg(res.msg);
                    }else{
                       openCheckPro(id,list,goods_id);
                       checkProTimer = setInterval(function(){
                           refreshCheckPro(id)
                       },1500)
                    }
                },'json')
            });
            //实时刷新检查标品数据
            function refreshCheckPro(id){
                $.post("/admin/standard/checkProInfo",{'id':id},function(res){
                    var list = res.data.tips;
                    var goods_id = res.data.goods_id;
                    if(list.length<1){
                        layer.msg(res.msg);
                    }else{
                        showCheckProResult(id,list,goods_id)
                    }
                },'json')
            }

            function showCheckProResult(id,data,goods_id){
                var showLink = true;
                var str = "";
                str += '<div class="layui-form-item">检测信息如下：</div>';
                $.each(data,function(i,v){
                    str += '<div class="layui-form-item">\n' +
                        '<label class="layui-form-label">'+i+'</label>\n' +
                        '<div class="layui-input-inline" style="margin:8px auto;">\n';
                    if(v=="1"){
                        str += '<i class="layui-icon isok">&#xe605;</i>\n';
                    }else{
                        str += '<i class="layui-icon notok">&#x1006;</i>\n';
                        if(showLink){
                            var url = checkLinkUrl(id,i,goods_id);
                            var url_class = "";
                            if(i=="商品套餐"){
                                url_class = "a_menu";
                            }
                            str += '<a href="'+url+'" class="layui-btn layui-btn-xs layui-btn-primary '+url_class+'" target="_blank" style="margin-top:-10px;margin-left:50px;">设置</a>\n';
                        }
                        showLink = false;
                    }
                    str += '</div>\n' +
                        '</div>';
                })
                $("#checkInfo").children().remove();
                $("#checkInfo").append(str);
                upPro = showLink;
                if(upPro){
                    clearInterval(checkProTimer);
                }
                return upPro;
            }
            //检测标品数据
            function openCheckPro(id,data,goods_id){
                upPro = showCheckProResult(id,data,goods_id);
                //打开一个弹窗 点击保存触发事件
                layer.open({
                    type: 1,
                    area: ['50%', '70%'],
                    btn: ['上架','取消'],
                    content: $('#ceshi'),
                    yes: function(index, layero) {
                        if(!upPro){
                            layer.msg("请补全以上缺省的信息！");
                            return false;
                        }
                        $.post("/admin/standard/changeToB",{'id':id,'show_toB':1},function(res){
                            layer.msg(res.msg);
                            if(res.code == 1) {
                                setTimeout(function(){
                                    location.href = res.url;
                                },1500)
                            }
                        },'json')
                    },btn2:function(index){
                        clearInterval(checkProTimer);
                        layer.close(index);
                    },end:function(){
                        clearInterval(checkProTimer);
                    }
                })
            }

            //检测toB上架所需跳转链接
            function checkLinkUrl(id,name="",goods_id=0){
                var url = "";
                switch (name) {
                    case "关联商品":
                        url = "{:url('admin/standard/detail')}?id="+id+"#sourceBox";
                        break;
                    case "关联行程":
                        url = "{:url('admin/standard/detail')}?id="+id+"#tripBox";
                        break;
                    case "商品套餐":
                        url = "{:url('admin/goods/addclassify')}?id="+goods_id;
                        break;
                    case "商品价格":
                        url = "{:url('admin/goods/personsedit')}?id="+goods_id+"&standard_id="+id;
                        break;
                    case "产品分类":
                        url = "{:url('admin/standard/detail')}?id="+id+"#tagForm";
                        break;
                    default:
                        url = "";
                        break;
                }
                return url;
            }
            //切换是否toB显示
            form.on('switch(changeToB)', function(data){
                var id= $(this).attr('data-id')
                var is_show;

                if(data.elem.checked){
                    is_show =1;
                }else{
                    is_show =0;
                }
                $.ajax({
                    url:"{:url('admin/standard/changeToB')}",
                    data:{'id':id,'show_toB':is_show},
                    type:'post',
                    async: false,
                    success:function(res) {
                        layer.msg(res.msg);
                    }
                })
            });
            //切换推荐状态
            form.on('switch(changeRecommend)', function(data){
                var id= $(this).attr('data-id')
                var is_recommend;

                if(data.elem.checked){
                    is_recommend =1;
                }else{
                    is_recommend =0;
                }
                $.ajax({
                    url:"{:url('admin/standard/changeRecommend')}",
                    data:{'id':id,'is_recommend':is_recommend},
                    type:'post',
                    async: false,
                    success:function(res) {
                        layer.msg(res.msg);
                    }
                })

            });
            //切换小程序模板
            form.on('switch(changeAutoOnSale)', function(data){
                var id= $(this).attr('data-id')
                var auto_on_sale;

                if(data.elem.checked){
                    auto_on_sale =1;
                }else{
                    auto_on_sale =0;
                }
                $.ajax({
                    url:"{:url('admin/standard/changeAutoOnSale')}",
                    data:{'id':id,'auto_on_sale':auto_on_sale},
                    type:'post',
                    async: false,
                    success:function(res) {
                        layer.msg(res.msg);
                    }
                })

            });
            //修改排序
            $("input[name=sortNum]").blur(function(){
                var oldValue = $(this).attr("old-value");
                var value = $(this).val();
                if(value=='' || value==undefined || parseInt(value) < 0){
                    layer.msg('请输入大于或等于0的数值');return false;
                }
                if(parseInt(oldValue)==parseInt(value)){
                    //未修改直接返回
                    return false;
                }
                var id = $(this).attr("data-id");
                if(parseInt(id) < 1){
                    layer.msg('数据错误，请刷新页面后重试');return false;
                }
                $.ajax({
                    url:"{:url('admin/standard/changeSortNum')}",
                    data:{'id':id,'sortNum':value},
                    type:'post',
                    async: false,
                    success:function(res) {
                        layer.msg(res.msg);
                    }
                })
            })
            //触发事件
            var active = {
                tabAdd: function(){
                    //新增一个Tab项
                    element.tabAdd('myselfgoods', {
                        title: '编辑商品' //用于演示
                        ,content: '内容'+ (Math.random()*1000|0)
                        ,id: new Date().getTime() //实际使用一般是规定好的id，这里以时间戳模拟下
                    })
                }
            };
            //框架内打开新窗口
            $('.myselfgoods').click(function(){
                var id = $(this).attr('data-id');
                var url = "{:url('admin/goods/addgoods')}?id="+id;
                layer.open({
                    title:'编辑自营商品',
                    type:2,
                    content:url,
                    area: ['60%', '90%'],
                    end:function(){
                        location.reload();
                    }
                });
            })
            $('.viatorgoods').click(function(){
                var id = $(this).attr('data-id');
                var url = "{:url('admin/goods/addgoodsother')}?id="+id;
                layer.open({
                    title:'编辑viator商品',
                    type:2,
                    content:url,
                    area: ['60%', '90%'],
                    end:function(){
                        location.reload();
                    }
                });
            })

            $(".setStandardInfo").click(function(){
                var url = $(this).attr('href');
                layer.open({
                    title:'编辑标品',
                    type:2,
                    content:url,
                    area: ['80%', '90%']
                });
                return false;
            })
            //销量排序
            $(".salesSortAsc").click(function(){
                $("input[name=order_param]").val("goodssales asc");
                $(".searchBtn").click();
            })
            $(".salesSortDesc").click(function(){
                $("input[name=order_param]").val("goodssales desc");
                $(".searchBtn").click();
            })
            //销量排序
            $(".viewSortAsc").click(function(){
                $("input[name=order_param]").val("view_count asc");
                $(".searchBtn").click();
            })
            $(".viewSortDesc").click(function(){
                $("input[name=order_param]").val("view_count desc");
                $(".searchBtn").click();
            })
        });
    </script>

</div>
</body>
</html>
